#include<stdio.h>
#include<string.h>
#include<stdlib.h>

const char *GetUserName()
{
    //用getenv获取环境变量，获取用户名
    const char *name = getenv("USER");
    return name == NULL ? "None" : name;
}

//获取主机名
const char *GetHostName()
{
    const char *hostname = getenv("HOSTNAME");
    return hostname == NULL ? "None" : hostname;
}

//当前主机路径
//cwd或pwd都可以
//"cwd" 是 "current working directory" 的缩写，意为“当前工作目录”
const char *GetPwd()
{
    const char *pwd = getenv("PWD");
    return pwd == NULL ? "None" : pwd;
}

int main()
{
    printf("[%s@%s %s]# ", GetUserName(), GetHostName(), GetPwd()); 
    return 0;
}
